package cn.wlinker.video.monitor.domain;

import lombok.Data;

@Data
public class R<T> {
    public static int SUCCESS = 1;
    public static int EXCEPT = 0;
    public static int ERROR = -1;
    public static int NOAUTH = -2;
    public static String SUMESSAGE = "操作成功";
    public static String TITLE_DEFAULT = "操作结果";
    public static String TTTLE_EXCEPT = "异常信息";
    public static String TTTLE_ERROR = "错误信息";
    private int code;
    private T detail;
    private String title;
    private String content;
    private Long rt;

    public R(int code, T detail, String title, String content, Long rt) {
        this.code = code;
        this.detail = detail;
        this.title = title;
        this.content = content;
        this.rt = rt;
    }

    public static <T> R<T> success() {
        return new R<>(SUCCESS, SUMESSAGE);
    }

    public static <T> R<T> status(Boolean status) {
        return Boolean.TRUE.equals(status) ? success() : err("操作失败");
    }

    public static <T> R<T> data(T data) {
        R<T> r = new R<>(SUCCESS, SUMESSAGE);
        r.setDetail(data);
        return r;
    }

    public R(int code, String title) {
        this.code = code;
        this.title = title;
    }

    public static <T> R<T> err(String err) {
        return new R<>(ERROR, err);
    }


}
